home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / sb / sb.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  250 lines

  1. /*    The Transactor Structure Browser (SB) V1.0
  2.  *    From Transactor Magazine, Volume 7, Issue 6
  3.  *
  4.  *    By Nick Sullivan and Chris Zamara (AHA!) (c) 1986
  5.  *
  6.  *    SB displays system structures via pointers found
  7.  *    in other structures. You start from IntuitionBase.
  8.  *
  9.  *    Structures implemented in V1.0:
  10.  *    IntuitionBase, Window, Screen, RastPort, BitMap, Gadget
  11.  *
  12.  *    Usage is through Intuition, clicking on a structure member
  13.  *    names to display info or a new structure.
  14.  *
  15.  *    *****  THIS PROGRAM MAY BE FREELY DISTRIBUTED  *****
  16.  */
  17.  
  18. /* include not needed for Aztec C using provided makefile */
  19.  
  20. /* I keep all the files in directory sb on df1:
  21.  * To keep the system happy, I 'ASSIGN SB: DF1:SB' then 'CD SB:'. GG.
  22.  */ 
  23.  
  24.  
  25. #include "sb:sb.h"
  26. #define MIN(x,y) ((x)<(y)?(x):(y))
  27. #define FLAGFIELDS 4
  28. extern struct IntuitionBase *IntuitionBase;
  29. extern struct IntuiText ChoiceText[], BackIText;
  30. APTR OpenLibrary ();
  31. int level = 0; /* current level of nesting */
  32. static char textlines[MAXGADG + 1][80];
  33. extern void PrIntuiBase(), HexLine();
  34.  
  35. void main()
  36. {
  37. int choice = -1;
  38.   SetupGadg();
  39.   OpenStuff(); /* open intuition library & window */
  40.   while (choice) {
  41.     putHeader("Choose a library structure", NULL);
  42.     ChoiceText[0].IText = (UBYTE *)" Intuition       struct Library";
  43.     BackIText.IText = (UBYTE *)"  Quit  Program";
  44.     switch (choice = GetChoice(1)) {
  45.       case 1:
  46.         PrIntuiBase ("The IntuitionBase structure", IntuitionBase);
  47.         break;
  48.     }
  49.   }
  50.   CloseOut();
  51. }
  52.  
  53.  
  54. void PrIntuiBase (string, IBase) char *string; struct IntuitionBase *IBase;
  55. {
  56. static struct StructData structdata[] = {
  57.      { "(LibMode",           "struct Library)", 0, SZ(Library) },
  58.      { "(ViewLord",          "struct View)",    0, SZ(View)    },
  59.      { " ActiveWindow",      "struct Window *", 5, PTRSIZE     },
  60.      { " ActiveScreen",      "struct Screen *", 5, PTRSIZE     },
  61.      { " FirstScreen",       "struct Screen *", 5, PTRSIZE     }
  62.   };
  63. int sum, choice = -1;
  64.   level++;
  65.   while (choice) {
  66.     sum = SetOptionText(string, structdata, (APTR)IBase, DATASIZE, 0);
  67.     switch (choice = GetChoice(DATASIZE)) {
  68.       case 3:
  69.         if (IBase->ActiveWindow)
  70.           PrWindow("The currently active window", IBase->ActiveWindow);
  71.         break;
  72.       case 4:
  73.         PrScreen("The currently active screen", IBase->ActiveScreen);
  74.         break;
  75.       case 5:
  76.         PrScreen("The first screen on Intuition's list", IBase->FirstScreen);
  77.         break;
  78.     }
  79.   }
  80.   level--;
  81. }
  82.  
  83.  
  84. void put (option, stuff, base, offset)
  85. int option; struct StructData *stuff; char *base; int offset;
  86. {
  87. register long lnum;
  88. register int  inum;
  89. char buf[40];
  90. int i;
  91.   sprintf(textlines[option], "%-16s%-24s", stuff->membername, stuff->membertype);
  92.   switch (stuff->printtype) {
  93.     case 0:            /* don't print anything */
  94.       buf[0] = '\0';
  95.       break;
  96.     case 1:            /* print a long */
  97.       lnum = *(long *)(base + offset);
  98.       sprintf(buf, "$%8lx  %0ld", lnum, lnum);
  99.       break;
  100.     case 2:            /* print an int */
  101.       inum = *(short *)(base + offset);
  102.       sprintf(buf, "$%8x  %10d", inum, inum);
  103.       break;
  104.     case 3:            /* print a byte */
  105.       inum = *(base + offset);
  106.       sprintf(buf, "$%8x  %10d", inum, inum);
  107.       break;
  108.     case 4:            /* print a string */
  109.       if (!(lnum = *(long *)(base + offset) ))
  110.         sprintf(buf, "NULL");
  111.       else {
  112.         for (i = 0; i < 30 && *((char *)lnum + i); i++)
  113.           buf[i + 1] = *((char *)lnum + i);
  114.         buf[0] = buf[i + 1] = '\"';
  115.         buf[i + 2] = '\0';
  116.         if (*((char *)lnum + i))
  117.           strcat(buf, "...");
  118.       }
  119.       break;
  120.     case 5:            /* print a pointer */
  121.       if (!(lnum = *(long *)(base + offset) ))
  122.         sprintf(buf, "NULL");
  123.       else
  124.         sprintf(buf, "$%8lx  %10ld", lnum, lnum);
  125.       break;
  126.     case 11:            /* print a long */
  127.       lnum = *(long *)(base + offset);
  128.       sprintf(buf, "$%8lx  %10lu", lnum, lnum);
  129.       break;
  130.     case 12:            /* print an int */
  131.       inum = *(short *)(base + offset);
  132.       sprintf(buf, "$%8x  %10u", inum, inum);
  133.       break;
  134.     case 13:            /* print a byte */
  135.       inum = *(base + offset);
  136.       sprintf(buf, "$%8x  %10u", inum, inum);
  137.       break;
  138.   }
  139.   strcat(textlines[option], buf);
  140.   ChoiceText[option].IText = (UBYTE *)textlines[option];
  141. }
  142.  
  143.  
  144. void FlagPrint(string, names, flags)
  145. char *string, **names; ULONG flags;
  146. {
  147. int i, line, fields = FLAGFIELDS;
  148. char buf[32];
  149.   SetBackText(1); /* 'prev level' */
  150.   for (i = 0; i < 8; i++) {
  151.     strcpy(textlines[i], "-");
  152.     ChoiceText[i].IText = (UBYTE *)textlines[i];
  153.   }
  154.   putHeader(string, NULL);
  155.   for (i = line = 0; i < 32; i++) {
  156.     if ((flags & (1L << i)) && names[i]) {
  157.       sprintf(buf, "%-19s", names[i]);
  158.       strcat(textlines[line], buf);
  159.       if (!--fields) {
  160.         ChoiceText[line].IText = (UBYTE *)textlines[line];
  161.         line++;
  162.         fields = FLAGFIELDS;
  163.       }
  164.     }
  165.   }
  166.   if (fields < FLAGFIELDS)
  167.     ChoiceText[line].IText = (UBYTE *)textlines[line];
  168.   while (GetChoice(line + 1))
  169.     ;
  170. }
  171.  
  172.  
  173. void HexDump(string, address, unit, size)
  174. char *address, *string; int unit; long size;
  175. {
  176. int line = 0, c;
  177. char *buf[80];
  178.   BackIText.IText = (UBYTE *)" Exit Hex Dump  ";
  179.   if (size == -1)
  180.     size = 0x7ffff;
  181.   do {
  182.     sprintf(buf, "%s from %lx (%ld)", string, address, address);
  183.     putHeader(buf, NULL);
  184.     if (line == MAXGADG)
  185.       line = 0;
  186.     while (line < MAXGADG && size > 0) {
  187.       HexLine(address, unit, line++, size);
  188.       size -= 16;
  189.       address += 16;
  190.     }
  191.     c = GetChoice(size > 0 ? MAXGADG + 1 : line);
  192.   } while (size > 0 && c == MOREGADG);
  193. }
  194.  
  195.  
  196. void HexLine (address, unit, line, size)
  197. UBYTE *address; int unit, line; long size;
  198. {
  199. USHORT i, j;
  200. char buf[80];
  201. static char hexdigit[] = "0123456789ABCDEF";
  202.   sprintf(textlines[line], "-%6lx: ", address);
  203.   for (i = 0; i < MIN(size, 16); i += unit) {
  204.     switch (unit) {
  205.       case BYTESIZE:
  206.         j = *(address + i);
  207.         sprintf(buf, "%c%c ", hexdigit[j / 16], hexdigit[j % 16]);
  208.         break;
  209.       case INTSIZE:
  210.         sprintf(buf, "%04x ", *(short *)(address + i));
  211.         break;
  212.       case PTRSIZE:
  213.         sprintf(buf, "%08lx ", *(long *)(address + i));
  214.         break;
  215.     }
  216.     strcat(textlines[line], buf);
  217.   }
  218.   ChoiceText[line].IText = (UBYTE *)textlines[line];
  219. }
  220.  
  221.  
  222. int SetOptionText (hdrtext, data, object, size, offset)
  223. char *hdrtext;
  224. struct StructData *data;
  225. APTR object;
  226. int size, offset;
  227. {
  228. int i, sum;
  229.   SetBackText( offset ? 1 : 0);
  230.   putHeader(hdrtext, object);
  231.   for (i = sum = 0; i < size; i++) {
  232.     put(i, &data[i], object, sum + offset);
  233.     sum += data[i].datasize;
  234.   }
  235.   return (sum + offset);
  236. }
  237.     
  238.  
  239. void PrString(heading, string) char *heading, *string;
  240. {
  241. char *newstring, *malloc();
  242.   putHeader(heading, NULL);
  243.   newstring = malloc(strlen(string) + 1);
  244.   *newstring = '-';
  245.   strcpy(newstring + 1, string);
  246.   ChoiceText[0].IText = (UBYTE *)newstring;
  247.   GetChoice(1);
  248.   free(newstring);
  249. }
  250.